package com.tgy.jd.controller;

import com.tgy.jd.service.ContentService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/***
 * @ClassName: ContentController
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 17:43 2022/3/2
 * @version : V1.0
 */
@RestController
@Slf4j
@Api(value = "京东实战", tags = {"爬虫处理接口"})
public class ContentController {
    @Resource
    ContentService contentService;


    @ApiOperation(value = "爬取京东消息并存入ES")
    @ApiImplicitParam(paramType="path", name = "keyword", value = "关键字", required = true, dataType = "String")
    @GetMapping("/parse/{keyword}")
    public Boolean parse(@PathVariable("keyword") String keyword){
        log.info("输入参数为{}",keyword);
         return contentService.parseContext(keyword);
    }


    @ApiOperation(value = "分页查询ES数据")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "keyword", value = "关键字", dataType = "String"),
            @ApiImplicitParam(paramType = "path", name = "pageNum", value = "页码", dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "pageSize", value = "页大小", dataType = "Integer")
    })
    @GetMapping("/search/{keyword}/{pageNum}/{pageSize}")
    public List<Map<String, Object>> search(@PathVariable("keyword") String keyword,
                                            @PathVariable("pageNum") int pageNum,
                                            @PathVariable("pageSize") int pageSize){
        log.info("输入参数为{}/{}/{}",keyword,pageNum,pageSize);
        return contentService.searchPageHighlight(keyword,pageSize,pageNum);

    }

    @GetMapping("/aa")
    public  String aa(@RequestParam("str") String str){
        System.out.println(str);
        return str;
    }

}
